home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <winb.h>
- #include <te.h>
- #include <fntb.h>
- #include <gui.h>
- #include <egb.h>
- #include <guidbg.h>
- #include <file_dlg.h>
- #include "neko.h"
-
- int aplid;
-
- void main(int argc, char *argv[])
- {
- MMICTRL ctrl;
- extern int APL_init();
-
- ctrl.displayPage = SCREENAVAILABLE;
- ctrl.mode = SCREENAVAILABLE;
- ctrl.page0 = SCREENIGNORE;
- ctrl.page1 = SCREENIGNORE;
- ctrl.size = 0;
- ctrl.ptr = NULL;
- ctrl.asize = 0;
- ctrl.aptr = NULL;
- ctrl.white = 15;
- ctrl.black = 8;
- ctrl.gray = 7;
- ctrl.xor = 7;
-
- if (MMI_Open(&ctrl) != NOERR){
- MMI_Close();
- return;
- }
- if (APL_init(argc, argv) != NOERR){
- MMI_Close();
- return;
- }
- MMI_ExecSystem();
- MMI_Close();
- }
-
- int task_mode = 0x03;
- int do_unmap = FALSE;
-
- APL_init(int argc, char **argv)
- {
- extern int timer, frame16, frame32k;
- extern int userFunc();
- extern void nekomain();
- extern void active_check();
-
- while (--argc > 0){
- argv++;
- if (strcmp(*argv, "-t") == 0 && argc > 1){
- timer = atoi(*++argv);
- argc--;
- } else if (strcmp(*argv, "-m") == 0 && argc > 1){
- task_mode = atoi(*++argv);
- argc--;
- } else if (strcmp(*argv, "-unmap") == 0){
- do_unmap = TRUE;
- } else if (strcmp(*argv, "-nf") == 0){
- frame16 = frame32k = FALSE;
- }
- }
- aplid = MMI_GetApliId();
- active_check(TRUE);
- MMI_SendMessage(MMI_GetBaseObj(), MM_SETEXEC, 1, userFunc);
- MMI_CallMessage(aplid, GM_TITLE, (int)"NEKO", 0);
- if (task_mode & 0x01)
- MMI_SetIdleTaskFunc(nekomain);
- if (task_mode & 0x02)
- MMI_SetIntervalFunc(nekomain);
- MMI_CallMessage(aplid, GM_SLEEP, 0, 0);
- return (NOERR);
- }
-
- int (**winfunc)();
-
- connect_server()
- {
- int server;
-
- if ((server = MMI_CallMessage(aplid, GM_QUERYID, QM_SAMEAS, (int)SERVER))
- > NOERR){
- if (MMI_CallMessage(server, GM_EXECUSER, 0, 0) != MAGIC)
- server = NOERR; /* not ready */
- else
- winfunc = (int (**)())MMI_CallMessage(server, GM_EXECUSER, 1, 0);
- #ifdef DEBUG
- printf("NEKO: server = %d, winfunc = 0x%x\n", server, winfunc);
- #endif
- } else {
- #ifdef DEBUG
- printf("NEKO: server = %d\n", server);
- #endif
- server = NOERR;
- }
- return (server);
- }
-
- int server = NOERR;
- int server_die = FALSE;
- int own = FALSE;
- int active = FALSE;
- int restart = TRUE;
- int unmapped = FALSE;
- short vramseg;
- u_long vramoff;
- int pixel, fbwidth, dwidth, vheight;
- RESOLUTION mode = { 0, 0, 0, 0, 0, 0, };
-
- void active_check(int init)
- {
- int owner;
- char *title;
- SCRNDATA screen;
- extern int neko_first, neko_count;
- extern int modecmp();
- extern void setup();
-
- if (server == NOERR){
- if ((server = connect_server()) > NOERR){
- init = TRUE;
- restart = TRUE;
- neko_first = TRUE;
- neko_count = 1;
- }
- }
- if (server <= NOERR){
- server = NOERR;
- restart = TRUE;
- neko_count = 1;
- return;
- }
- owner = MMI_CallMessage(aplid, GM_QUERYID, QM_BACKPAGE, 0);
- title = (char *)MMI_CallMessage(owner, GM_TITLE, (int)NULL, 0);
- #ifdef DEBUG
- printf("NEKO: BACKPAGE owner is %s\n", title);
- #endif
- MMI_CallMessage(owner, GM_SCRNDATA, FALSE, (int)&screen);
- if (init){
- if (strcmp(title, OWNER) == 0){
- own = TRUE;
- mode = screen.page[1];
- setup(&screen.page[1]);
- } else {
- own = active = FALSE;
- }
- return;
- }
- if (own){
- if (strcmp(title, OWNER) == 0){
- if (modecmp(&mode, &screen.page[1]) != 0){
- #ifdef DEBUG
- printf("NEKO: mode change\n");
- #endif
- mode = screen.page[1];
- setup(&screen.page[1]);
- }
- } else {
- own = active = FALSE;
- }
- } else {
- if (strcmp(title, OWNER) == 0){
- own = TRUE;
- setup(&mode);
- }
- }
- #ifdef DEBUG
- printf("NEKO: own=%d, active=%d, restart=%d\n", own, active, restart);
- #endif
- }
-
- void setup(RESOLUTION *page1)
- {
- extern int neko_count;
-
- restart = TRUE;
- neko_count = 1;
- pixel = page1->pixel;
- fbwidth = page1->byte;
- dwidth = page1->dx;
- vheight = page1->vy;
- vramseg = page1->segment;
- vramoff = (u_long)page1->offset;
- active = (pixel == 4 || pixel == 16);
- unmapped = FALSE;
- }
-
- modecmp(RESOLUTION *a, RESOLUTION *b)
- {
- return (memcmp(a, b, sizeof (RESOLUTION) - sizeof (short)));
- }
-
- userFunc(int apliId, int messId, int info, int data)
- {
- int ret;
- extern int neko_count;
- extern void terminate(), map();
-
- ret = ILLEGAL_FUNCTION ;
-
- switch (messId){
- case GM_EXECUSER: /* server die */
- #ifdef DEBUG
- printf("NEKO: server die\n");
- #endif
- server_die = TRUE;
- server = NOERR;
- active = FALSE;
- terminate();
- break;
- case GM_PRESCRCHG:
- #ifdef DEBUG
- printf("NEKO: POSTSCRCHG\n");
- #endif
- if (!server_die && do_unmap){
- map(FALSE);
- neko_count = 1;
- }
- ret = NOERR;
- break;
- case GM_POSTSCRCHG:
- #ifdef DEBUG
- printf("NEKO: POSTSCRCHG\n");
- #endif
- if (server_die)
- server_die = FALSE;
- else
- active_check(FALSE);
- ret = NOERR;
- break;
- case GM_QUIT:
- terminate();
- MMI_SetHaltFlag(TRUE);
- ret = NOERR;
- break;
- case GM_PURGE:
- case GM_ENVIRONMENT:
- case GM_SHOW:
- case GM_ERASE:
- ret = NOERR;
- break;
- }
- return (ret);
- }
-